<?php

/* @var $this \yii\web\View */
/* @var $content string */

use app\models\Config;
use app\models\QuarterSetting;
use app\models\User;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;

/** @var \app\models\User $user */
$user = Yii::$app->user->identity->user;

$config = \yii\helpers\ArrayHelper::map(Config::find()->asArray()->all(), 'key', 'value');

$messages = \app\models\Message::findAll([
    'user_id' => $user->id,
    'if_read' => false,
]);

$quarterSetting = QuarterSetting::findOne(['is_open'=>true,'is_close'=>false]);
global $count;
$count = QuarterSetting::find()->andWhere(['is_open'=>false,])->count();
?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <base href="/">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <link rel="stylesheet" href="/css/select2.min.css">
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/icon.css">
    <link rel="stylesheet" href="/css/main.css">
    <link rel="stylesheet" href="/css/_all-skins.css">

    <script src="/js/jquery-1.9.1.min.js"></script>
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script src="/js/global-info.js"></script>
    <script src="/js/query2object.js"></script>
    <script src="/js/slimscrol.js"></script>
    <script src="/js/select2.full.min.js"></script>
    <script src="/js/fastclick.js"></script>
    <script src="/js/abcd.js"></script>
    <script src="/js/demo.js"></script>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition skin-green-light sidebar-mini">

<div class="wrapper">
    <header class="main-header">
        <!-- Logo -->
        <a class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini"><b>A</b>LT</span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg"><b>Admin</b>LTE</span>
        </a>

        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top">
            <!-- Sidebar toggle button-->
            <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
                <span class="sr-only">切换导航显示</span>
            </a>
            <!-- Navbar Right Menu -->
            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">
                    <li>
                        <a href="javascript:">
                            当前处于<?= $quarterSetting ? "第{$quarterSetting->id}财年" : '财年关闭状态'?>，
                            还剩<?=$count?>个财年。
                        </a>
                    </li>
                    <!-- User Account: style can be found in dropdown.less -->
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <span class="hidden-xs"><?= $user->username ?></span>
                        </a>
                        <ul class="dropdown-menu">
                            <!-- User image -->
                            <?php if($user->role == User::ROLE_PRODUCER) { ?>
                            <li class="user-header" style="padding: 4px">
                                <p>货币 ： <?= $user->current_currency ?></p>
                                <p>科技值 ： <?= $user->tech_level ?></p>
                                <p>原料树等级 ： <?= $user->material_level ?></p>
                                <p>净资产 ： <?= $user->current_netasset ?></p>
                                <p>净资产增长率 ： <?= $user->netasset_growth ?></p>
                            </li>
                            <?php } if($user->role == User::ROLE_TRADER or $user->role == User::ROLE_GOV or $user->role == User::ROLE_ADMIN) { ?>
                                <li class="user-header" style="padding: 25px">
                                    <p>货币 ： <?= $user->current_currency ?></p>
                                    <p>净资产 ： <?= $user->current_netasset ?></p>
                                    <p>净资产增长率 ： <?= $user->netasset_growth ?></p>
                                </li>
                            <?php } ?>
                            <!-- Menu Body -->
                            <li class="user-body">
                                <p class="text-center" style="font-size: 1.5em;">用户名： <?= $user->username ?></p>
                                <p class="text-center" style="font-size: 1.5em;">角色： <?= $user->country ? $user->country->name : '' ?><?= $user->roleStr ?></p>
                            </li>
                        </ul>
                    </li>
                    <li class="dropdown notifications-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <i class="fa fa-bell-o"></i>
                            <span class="label label-warning"><?=count($messages)?></span>
                        </a>
                        <?php if(count($messages)>0) { ?>
                        <ul class="dropdown-menu">
                            <li class="header">您有 <?=count($messages)?> 条新消息</li>
                            <li>
                                <!-- inner menu: contains the actual data -->
                                <ul class="menu">
                                    <?php foreach($messages as $message) { ?>
                                        <li>
                                            <a href="/site/message?id=<?=$message->id?>">
                                                <i class="<?=$message->color?>"></i> <?=$message->title?>
                                            </a>
                                        </li>
                                    <?php } ?>
                                </ul>
                            </li>
                        </ul>
                        <?php } ?>
                    </li>
                    <li>
                        <a href="/site/password"><i class="fa fa-cog"></i>修改密码</a>
                    </li>
                    <li>
                        <a href="/site/login"><i class="fa fa-sign-out"></i>退出</a>
                    </li>
                </ul>
            </div>

        </nav>
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">
            <!-- sidebar: style can be found in sidebar.less -->
            <section class="sidebar">
                <!-- Sidebar user panel -->
                <div class="user-panel">
                    <div class="pull-left image">
                        <img src="/images/user2.jpg" class="img-circle" alt="User Image">
                    </div>
                    <div class="pull-left info">
                        <p><?= $user->username ?></p>
                        <i class="fa fa-circle text-success"></i> <?= $user->country ? $user->country->name : '' ?><?= $user->roleStr ?>
                    </div>
                </div>
            <?php if($user->role == User::ROLE_PRODUCER) { ?>
                <ul class="sidebar-menu" data-widget="tree">
                    <!-- <li class="header">生产商管理</li> -->
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-home"></i> <span>信息中心</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/news/notice"><i class="fa fa-angle-right"></i> 公告</a></li>
                            <li><a href="/news/index"><i class="fa fa-angle-right"></i> 新闻</a></li>
                        </ul>
                    </li>
                    <li>
                        <a href="/member/index">
                            <i class="fa fa-users"></i> <span>成员管理</span>
                            <span class="pull-right-container">
                              <small class="label pull-right bg-green">当前 <?= $user->getMembers()->count() ?> 人</small>
                            </span>
                        </a>
                    </li>
                    <li>
                        <a href="/material/index">
                            <i class="fa fa-sitemap"></i> <span>原料水晶</span>
                            <span class="pull-right-container">
                              <small class="label pull-right bg-green">当前 <?= $user->material_level ?> 级</small>
                            </span>
                        </a>
                    </li>
                    <li>
                        <a href="/user/material">
                            <i class="fa fa-table"></i> <span>原料库存</span>
                        </a>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-flask"></i> <span>产品研发</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/product/design"><i class="fa fa-angle-right"></i> 设计提交</a></li>
                            <li><a href="/product/index"><i class="fa fa-angle-right"></i> 设计查看</a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-wrench"></i> <span>产品生产</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/product/product"><i class="fa fa-angle-right"></i> 生产定价</a></li>
                            <li><a href="/user/product"><i class="fa fa-angle-right"></i> 产品库存</a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-legal"></i> <span>交易平台</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/order/product"><i class="fa fa-angle-right"></i> 待售产品</a></li>
                            <li><a href="/order/index"><i class="fa fa-angle-right"></i> 交易订单
                                    <span class="pull-right-container">
                              <span class="label label-primary pull-right"><?= $user->getOrders()->andWhere(['status'=>2])->count() ?></span>
                            </span></a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-credit-card"></i> <span>政府贷款</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/loan/add"><i class="fa fa-angle-right"></i> 贷款申请</a></li>
                            <li><a href="/loan/index"><i class="fa fa-angle-right"></i> 偿还贷款
                                    <span class="pull-right-container">
                              <span class="label label-primary pull-right"><?= $user->getLoans()->andWhere(['status'=>3])->count() ?></span>
                            </span></a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-tasks"></i> <span>转账平台</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/transfer/add"><i class="fa fa-angle-right"></i> 资金转账</a></li>
                            <li><a href="/transfer/index"><i class="fa fa-angle-right"></i> 转账列表</a></li>
                        </ul>
                    </li>
                </ul>
            <?php } if($user->role == User::ROLE_TRADER) { ?>
                <ul class="sidebar-menu" data-widget="tree">
                    <li class="header">交易商管理</li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-home"></i> <span>信息中心</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/news/notice"><i class="fa fa-angle-right"></i> 公告</a></li>
                            <li><a href="/news/index"><i class="fa fa-angle-right"></i> 新闻</a></li>
                        </ul>
                    </li>
                    <li>
                        <a href="/member/index">
                            <i class="fa fa-users"></i> <span>成员管理</span>
                            <span class="pull-right-container">
                              <small class="label pull-right bg-green">当前 <?= $user->getMembers()->andWhere(['status'=>1])->count() ?> 人</small>
                            </span>
                        </a>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-legal"></i> <span>交易平台</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/order/product"><i class="fa fa-angle-right"></i> 待售产品</a></li>
                            <li><a href="/order/index"><i class="fa fa-angle-right"></i> 交易订单
                                    <span class="pull-right-container">
                              <span class="label label-primary pull-right"><?= $user->getOrders()->andWhere(['status'=>2])->count() ?></span>
                            </span></a></li>
                        </ul>
                    </li>
                    <li>
                        <a href="/user/product">
                            <i class="fa fa-table"></i> <span>产品库存</span>
                        </a>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-credit-card"></i> <span>政府贷款</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/loan/add"><i class="fa fa-angle-right"></i> 贷款申请</a></li>
                            <li><a href="/loan/index"><i class="fa fa-angle-right"></i> 偿还贷款
                                    <span class="pull-right-container">
                              <span class="label label-primary pull-right"><?= $user->getLoans()->andWhere(['status'=>3])->count() ?></span>
                            </span></a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-tasks"></i> <span>转账平台</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/transfer/add"><i class="fa fa-angle-right"></i> 资金转账</a></li>
                            <li><a href="/transfer/index"><i class="fa fa-angle-right"></i> 转账列表</a></li>
                        </ul>
                    </li>
                </ul>
            <?php } if($user->role == User::ROLE_GOV) { ?>
                <ul class="sidebar-menu" data-widget="tree">
<!--                    <li class="header">政府管理</li>-->
                    <li>
                        <a href="/member/index">
                            <i class="fa fa-users"></i> <span>成员管理</span>
                            <span class="pull-right-container">
                              <small class="label pull-right bg-green">当前 <?= $user->getMembers()->andWhere(['status'=>1])->count() ?> 人</small>
                            </span>
                        </a>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-file-text-o"></i> <span>政策制定</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/news/notice-add"><i class="fa fa-angle-right"></i> 政策发布</a></li>
                            <li><a href="/news/notice"><i class="fa fa-angle-right"></i> 政策列表</a></li>
                        </ul>
                    </li>
                    <li>
                        <a href="/product/auth"><i class="fa fa-check-square-o"></i> <span>设计审核</span></a>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-laptop"></i> <span>监管平台</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/country/user-list"><i class="fa fa-angle-right"></i> 实体信息</a></li>
                            <li><a href="/country/member-list"><i class="fa fa-angle-right"></i> 成员信息</a></li>
                            <li><a href="/country/product-list"><i class="fa fa-angle-right"></i> 产品库存</a></li>
                            <li><a href="/country/order-list"><i class="fa fa-angle-right"></i> 订单列表</a></li>
                            <li><a href="/country/tax"><i class="fa fa-angle-right"></i> 关税设置</a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-credit-card"></i> <span>贷款平台</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/country/loan"><i class="fa fa-angle-right"></i> 贷款审核</a></li>
                            <li><a href="/country/loan-rate"><i class="fa fa-angle-right"></i> 利率设置</a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-file-text-o"></i> <span>新闻宣传</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/news/add"><i class="fa fa-angle-right"></i> 新闻发布</a></li>
                            <li><a href="/news/index"><i class="fa fa-angle-right"></i> 新闻列表</a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-tasks"></i> <span>转账平台</span>
                            <span class="pull-right-container">
                              <i class="fa fa-angle-left pull-right"></i>
                            </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/transfer/add"><i class="fa fa-angle-right"></i> 资金转账</a></li>
                            <li><a href="/transfer/index"><i class="fa fa-angle-right"></i> 转账列表</a></li>
                        </ul>
                    </li>
                </ul>
            <?php } if($user->role == User::ROLE_ADMIN) { ?>
                <ul class="sidebar-menu" data-widget="tree">
<!--                    <li class="header">组委会管理</li>-->
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-home"></i> <span>信息中心</span>
                            <span class="pull-right-container">
                          <i class="fa fa-angle-left pull-right"></i>
                        </span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/news/notice"><i class="fa fa-angle-right"></i> 公告</a></li>
                            <li><a href="/news/index"><i class="fa fa-angle-right"></i> 新闻</a></li>
                            <li><a href="/news/notice-add"><i class="fa fa-angle-right"></i> 公告发布</a></li>
                        </ul>
                    </li>
                    <li><a href="/admin/material/"><i class="fa fa-sitemap"></i> <span>原料水晶</span></a></li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-laptop"></i> <span>监管平台</span>
                            <span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/admin/user/"><i class="fa fa-angle-right"></i> <span>用户信息</span></a></li>
                            <li><a href="/admin/member/"><i class="fa fa-angle-right"></i> <span>成员信息</span></a></li>
                            <li><a href="/admin/country/"><i class="fa fa-angle-right"></i> <span>国家信息</span></a></li>
                            <li><a href="/admin/user-log/"><i class="fa fa-angle-right"></i> <span>用户操作记录</span></a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-legal"></i> <span>交易平台</span>
                            <span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/order/product"><i class="fa fa-angle-right"></i> 待售产品</a></li>
                            <li><a href="/order/index"><i class="fa fa-angle-right"></i> 交易订单
                                    <span class="pull-right-container">
                              <span class="label label-primary pull-right"><?= $user->getOrders()->andWhere(['status'=>2])->count() ?></span>
                            </span></a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-gears"></i> <span>系统设置</span>
                            <span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="/admin/quarter-setting/"><i class="fa fa-angle-right"></i> <span>财年设置</span></a></li>
                            <li><a href="/admin/transfer/"><i class="fa fa-angle-right"></i> <span>转账管理</span></a></li>
                            <li><a href="/admin/config/"><i class="fa fa-angle-right"></i> <span>升级配置信息</span></a></li>
                            <li><a href="/admin/loan-rate/"><i class="fa fa-angle-right"></i> <span>贷款利率管理</span></a></li>
                            <li><a href="/admin/user-product/"><i class="fa fa-angle-right"></i> <span>用户产品库存管理</span></a></li>
                            <li><a href="/admin/user-material/"><i class="fa fa-angle-right"></i> <span>用户原料库存管理</span></a></li>
                            <li><a href="/admin/order/"><i class="fa fa-angle-right"></i> <span>订单管理</span></a></li>
                        </ul>
                    </li>
                </ul>
            <?php } ?>
            </section>
        </aside>



    <div class="content-wrapper">
        <?= $content ?>
    </div>
    <!--底部-->
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 2.4.0
        </div>
        <strong>Copyright &copy; 2014-2016 <a>Almsaeed Studio</a>.</strong> All rights
        reserved.
    </footer>
</div>

<div style="display: none;" id="global-info"><?=\yii\helpers\Json::encode([
        'user' => $user,
        'config' => $config,
        'quarterSetting' => $quarterSetting,
        'count' => $count,
    ]);?></div>
<script>
    var $item = $('.sidebar-menu a[href^="'+document.location.pathname+'"]:eq(0)');
    if($item.length > 0) {
        $item.closest('li').addClass('active').closest('ul').closest('li').addClass('active menu-open');
    } else {
        $('.sidebar-menu a').each(function(index,item) {
            console.log(document.location.pathname.indexOf($(item).attr('href')));
            if(document.location.pathname.indexOf($(item).attr('href'))===0) {
                $(item).closest('li').addClass('active').closest('ul').closest('li').addClass('active menu-open');
                return false;
            }
        });
    }
</script>
</body>
</html>
